﻿using System.Collections.Generic;
using System.Linq;
using Microsoft.SharePoint;
using SPContrib.Artifacts.Definitions;
using SPContrib.Extensions;

namespace SPContrib.Artifacts.Collections
{
    public class FeatureActionDefinitionCollection : IEnumerable<FeatureActionDefinition>
    {
        private List<FeatureActionDefinition> _definitions;
        private SPFeature _feature;

        internal FeatureActionDefinitionCollection(SPFeature feature)
        {
            this._feature = feature;

            SPFeatureProperty actions;
            if (feature.TryLocateProperty("actions", out actions))
            {
                this._definitions = new List<FeatureActionDefinition>
                    (
                        from action in actions.Value.Split(';')
                        select new FeatureActionDefinition(action, feature)
                    );
            }
        }

        public IEnumerator<FeatureActionDefinition> GetEnumerator()
        {
            return _definitions.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return _definitions.GetEnumerator();
        }
    }
}
